#include "QxSampleModuleFactory.hpp"
#include <Base/QxAbstractPlugin.hpp>

class QxSampleModuleFactory::QxSampleModuleFactoryPrivate
{
public:

  QxSampleModuleFactoryPrivate( QxSampleModuleFactory* me ) : m_self ( me ) {
    m_plugins = m_self->getPlugins<QxAbstractPlugin>();
  }

  QxSampleModuleFactory*         m_self;
  QList<QxAbstractPlugin*>       m_plugins;
};

const QxSampleModuleFactory& QxSampleModuleFactory::instance()
{
  static QxSampleModuleFactory factory;

  return factory;
}

QxSampleModuleFactory::~QxSampleModuleFactory()
{
}

QString QxSampleModuleFactory::description() const
{
  return tr( "Sample Module Factory" );
}

QStringList QxSampleModuleFactory::pluginNameList() const
{
  QStringList result;
  Q_FOREACH( const QxAbstractPlugin* plugin, _pd->m_plugins ) {
    result << plugin->name();
  }
  qSort( result );

  return result;
}

const QList<QxAbstractPlugin*>& QxSampleModuleFactory::plugins() const
{
  return _pd->m_plugins;
}

QxAbstractPlugin* QxSampleModuleFactory::findPluginByName( const QString& pluginName ) const
{
  QxAbstractPlugin* result = 0;
  Q_FOREACH( QxAbstractPlugin* plugin, plugins() ) {
    if( !plugin->name().compare( pluginName, Qt::CaseInsensitive ) ) {
      result = plugin;
      break;
    }
  }

  return result;
}

QxSampleModuleFactory::QxSampleModuleFactory()
  : QxAbstractFactory( "NEHE" ), _pd( new QxSampleModuleFactoryPrivate( this ) )
{
}
